{%- if storeConfig.snapchat_pixel_id|strtoarray -%}
        <!-- Snap Pixel Code -->
<script type='text/javascript'>
    (function (e, t, n) {
        if (e.snaptr) return;
        var a = e.snaptr = function () {
            a.handleRequest ? a.handleRequest.apply(a, arguments) : a.queue.push(arguments)
        };
        a.queue = [];
        var s = 'script';
        r = t.createElement(s);
        r.async = !0;
        r.src = n;
        var u = t.getElementsByTagName(s)[0];
        u.parentNode.insertBefore(r, u);
    })(window, document,
        'https://sc-static.net/scevent.min.js');

    {%- assign pixels = storeConfig.snapchat_pixel_id | strtoarray -%}
    {%- for pixel in pixels -%}
    snaptr('init', '{{ pixel }}', {'user_email': oemcart_user_email});
    {%- endfor -%}
	snaptr('track', 'PAGE_VIEW', {description: '{{ template }}'});

    {%- if template == 'product_detail' -%}

    {%- if product.id and product.variant.sku_code -%}
    snaptr('track', 'VIEW_CONTENT', {
        'currency': '{{ base_currency.standard_code }}',
        'price': "{{ product.variant.price }}",
        'item_category': '{{ product.product_type | escape | append: ' '}}'.replace(/\s+$/g, ""),
        'number_items': 1,
        'item_ids': ['{{ product.spu | escape}}']
    });
    {%- endif -%}

    {%- elsif template == 'search_detail' and search.keywords -%}
    snaptr('track', 'SEARCH', {'search_string': '{{ search.keywords | escape | append: ' ' }}'.replace(/\s+$/g, "")});


    {%- elsif template == 'order_success' -%}
    var productList=[];
    {%- for product in order.product -%}
    productList.push("{{ product.spu | escape}}");
    {%- endfor -%}
    snaptr('track', 'PURCHASE', {
        'currency': '{{ order.currency_code }}',
        'item_ids': productList,
        'number_items': '{{ order.total_num }}',
        {%- if storeConfig.snapchat_enable_ga -%}
        'price': "{{ order.current_subtotal_price| plus:order.current_coupon_price | plus:order.current_promotion_price }}",
        {%- else -%}
        'price': "{{ order.total_price }}",
        {%- endif -%}
        'transaction_id': '{{ order.order_number }}'
    });
    
    {%- endif -%}
</script>
<script type='text/javascript'>
    function callback_snapchat_add_to_cart(ecdata) {
        var ids = [];
        ids.push(ecdata['ec_data_spu']);
        snaptr('track', 'ADD_CART', {
            'currency': '{{ base_currency.standard_code }}',
            'price': ecdata['ec_data_price'] * ecdata['ec_data_quantity'],
            'number_items': ecdata['ec_data_quantity'],
            'item_category': ecdata['ec_data_category'],
            'item_ids': ids
        });
    }

    function callback_snapchat_generate_lead() {
        snaptr('track', 'SUBSCRIBE');
    }

    function callback_snapchat_login() {
        snaptr('track', 'LOGIN');
    }

    function callback_snapchat_begin_checkout() {
        snaptr('track', 'START_CHECKOUT');
    }

    function callback_snapchat_remove_from_cart(ec_data) {
        snaptr('track', 'remove_from_cart', {
        'currency': '{{ base_currency.standard_code }}',
        'price': ec_data['ec_data_price']*ec_data['ec_data_quantity'],
        'item_category': ec_data['ec_data_category'],
        'number_items': ec_data['ec_data_quantity'],
        'item_ids': ["ec_data['ec_data_spu']"]
        });
    }

    function callback_snapchat_share_product(ec_data, platform) {
        snaptr('track', 'SHARE', {
        'currency': '{{ base_currency.standard_code }}',
        'price': ec_data['ec_data_price'],
        'item_category': ec_data['ec_data_category'],
        'number_items': ec_data['ec_data_quantity'],
        'item_ids': ec_data['ec_data_spu']
        });
    }

    function callback_snapchat_add_address_information() {
        snaptr('track','PAGE_VIEW', {description:'ADD_ADDRESS_INFORMATION'});
    }

    function callback_snapchat_add_shipping_information() {
        snaptr('track','PAGE_VIEW', {description:'ADD_SHIPPING_INFORMATION'});
    }

    function callback_snapchat_add_payment_information() {
        snaptr('track','PAGE_VIEW', {description:'ADD_PAYMENT_INFORMATION'});
    }

    function callback_snapchat_sign_up() {
        snaptr('track', 'SIGN_UP');
    }
    function callback_snapchat_to_wishlist(){}
</script>

<!--End Snap Pixel Code -->
        {%- endif -%}

